import java.util.ArrayList;
import java.util.Scanner;

public class dish_main {
    static ArrayList<dish> orderlist = new ArrayList<>();
    static ArrayList<dish> menulist = new ArrayList<>();

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        while(true){
            showMenu();
            int input = sc.nextInt();

            switch (input) {
                case 1:
                    initDish();
                    while(true){
                        openMenu();
                        int input1 = sc.nextInt();
                        System.out.println("已选择菜品" + input1);
                        if (input1 == 0){
                            break;
                        }
                        orderlist.add(menulist.get(input1-1));
                        continue;
                    }
                break;
                case 2:
                    checkOrder();
                    continue;
                case 3:
                    Pay();
                    break;

            }
        }

    }

    public static void showMenu(){
        System.out.println("====请输入你要选择的选项前面的数字====");
        System.out.println("1.打开菜单");
        System.out.println("2.查看已点菜品");
        System.out.println("3.结账买单");
    }

    public static void initDish(){
        dish dish1 = new dish(1,"鱼香肉丝",48);
        menulist.add(dish1);
        dish dish2 = new dish(2,"宫保鸡丁",52);
        menulist.add(dish2);
        dish dish3 = new dish(3,"清蒸鲈鱼",57);
        menulist.add(dish3);
        dish dish4 = new dish(4,"麻婆豆腐",35);
        menulist.add(dish4);
        dish dish5 = new dish(5,"梅菜扣肉",50);
        menulist.add(dish5);
        dish dish6 = new dish(6,"水煮肉片",55);
        menulist.add(dish6);
    }

    public static void openMenu(){
        System.out.println("请选择你要点的菜品：");
        System.out.println("输入 “0” 返回主菜单");
        System.out.println("序号" + "\t" + "菜名" + "\t"+ "\t" + "价格");
        for (int i = 0; i < menulist.size(); i++) {
            dish dishes = menulist.get(i);
            System.out.println(dishes.getId() + "\t" + "\t" + dishes.getName() + "\t" +"\t" + dishes.getPrice());
        }
    }

    public static void checkOrder(){
        System.out.println("以下是已点菜品");
        for (int i = 0; i < orderlist.size(); i++) {
            dish dishes = orderlist.get(i);
            System.out.println(dishes.getId() + "\t" + "\t" + dishes.getName() + "\t" +"\t" + dishes.getPrice());
        }
    }

    public static void Pay(){
        System.out.println("正在结账中......");
        int total = 0;
        for (int i = 0; i < orderlist.size(); i++) {
            dish result = orderlist.get(i);
            int price = result.getPrice();

            total = total + price;
        }
        System.out.println("共消费了"+ total + "元");
    }
}
